Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  98] [ 4]  / answers: 1 / hits: 25172  / 13 Years ago, tue, november 29, 2011, 12:00:00

For example:



var Cars = {
1: { Make: Honda,
Model: Accord,
Color: Red
},
2: { Make: Honda,
Model: Civic,
Color: Silver
},
3: { Make: Honda,
Model: Jazz,
Color: Yellow
}


If I do a delete.Cars[2]; I will be left with Cars[1] and Cars[3].



I need a way (JS or jQuery) so that when I delete a key, the object reindexes. So, in the example above, I'm left with Cars[1] and Cars[2] (which was Cars[3]).


More From » jquery

 Answers
177

That is because you dont need the keys for the array.



var Cars = [
{
Make: Honda,
Model: Accord,
Color: Red
},{
Make: Honda,
Model: Civic,
Color: Silver
},{
Make: Honda,
Model: Jazz,
Color: Yellow
}
];

alert(Cars[1]['Make']); // Honda

[#88853] Sunday, November 27, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleykeyshawnb

Total Points: 281
Total Questions: 99
Total Answers: 111

Location: Saudi Arabia
Member since Sat, Aug 20, 2022
2 Years ago
;