Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Ppl,


I have an array as shown below, i would need to ignore the first row as the elements are not in order as 2 and 3... wouldn't want to sort instead ignore the row if its not in order

var cars = [
{year:2016,type:"Volvo"},
{type:"Saab", year:2001},
{type:"BMW", year:2010}]


any suggestions pls?

What I have tried:

i have no idea on how to acheive this,. if one of the element is missing i would tried with ownproperty ... but this has all elements... but it not in an order. experts thoughts pls
Posted
Updated 9-Mar-17 16:27pm

1 solution

There is no need to do that. Each array element is an object with the properties of year and type, their order is of no issue here, you get each object by their array index, e.g.
cars[0]
for the first object. To get the respective properties of the an element, say the 2nd elements,
cars[1].type
and
cars[1].year
Learn JavaScript Objects[^]
 
Share this answer
 
v3
Comments
Karthik_Mahalingam 9-Mar-17 23:14pm    
5
Peter Leow 10-Mar-17 0:46am    
Thank you, Karthik.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900