Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9069201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:22:00+00:00 2026-06-16T17:22:00+00:00

I have the array NatArray and the object NatObj ,This object I am pushing

  • 0

I have the array NatArray and the object NatObj ,This object I am pushing to
the former array ,but while retrieving its getting the last entry only ,
Here is my code

var tArray = [];
var tObj ;
tObj = {};
tObj.TranslatedLocIpAddr = 202116107;
tObj.TranslatedLocPort = 123;
tObj.LocIp = 50529027;
tObj.LocPort = 324;
tObj.LocPortRange = 5;
count = 0;
tArray.push(tObj) ;  

tObj.TranslatedLocIpAddr = 202116108;
tObj.TranslatedLocPort = 130;
tObj.LocIp = 67372036;
tObj.LocPort = 324;
tObj.LocPortRange = 5;
count = 1;
tArray.push(tObj) ;  

for (var i = 0; i <= count ;i++) {
    if( (tArray[i].TranslatedLocIpAddr == tGlobalIp)
     && (tArray[i].TranslatedLocPort == tGlobalPort) ) {
        alert("Existing t entry"); 
        return false;
    } 
}

I have verified the tArray[i].TranslatedLocIpAddr value, every time its
retrieving the last value in the array only.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:22:01+00:00Added an answer on June 16, 2026 at 5:22 pm

    Pushing an object into an array just puts a reference to the object into the array, not a copy of the object. So both your array elements point to the exact same object which will obviously contain all the properties that you last assigned to it. If you want to fix your code, then you need to actually create a second object like this:

    var tArray = [];
    var tObj ;
    tObj = {};
    tObj.TranslatedLocIpAddr = 202116107;
    tObj.TranslatedLocPort = 123;
    tObj.LocIp = 50529027;
    tObj.LocPort = 324;
    tObj.LocPortRange = 5;
    count = 0;
    tArray.push(tObj) ;  
    
    // create second object that is different from the first object
    tObj = {};
    tObj.TranslatedLocIpAddr = 202116108;
    tObj.TranslatedLocPort = 130;
    tObj.LocIp = 67372036;
    tObj.LocPort = 324;
    tObj.LocPortRange = 5;
    count = 1;
    tArray.push(tObj) ;  
    
    for (var i = 0; i <= count ;i++) {
        if( (tArray[i].TranslatedLocIpAddr == tGlobalIp)
         && (tArray[i].TranslatedLocPort == tGlobalPort) ) {
            alert("Existing t entry"); 
            return false;
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I have array object in jquery. array=[]; array{Id:user.Id,Date:user.Date}; Now am going to pass this
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
i have array in php, and i need work with this array in jQuery.
I have array like this abcArr = [[A, 10], [B, 20], [A,30],[C,40]] how can
I have array like this : Array ( [attribute] => Array ( [0] =>
I have array of objects with created images (Object.Image), i want to show images
I have array with colors as its objects. I want to create an image
I have array similar to this [ [0, 10]**, [1, 3]**, [5, 11]**, [14,
I have array like this: $test = array(20, 30, 40); And I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.