如果元素不在一个顺序中,如何忽略数组中的行 [英] How to ignore the row from array if elements are not in an order

查看:59
本文介绍了如果元素不在一个顺序中,如何忽略数组中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨Ppl,





我有一个如下所示的数组,我需要忽略第一行,因为元素是不按顺序排列为2和3 ...不想排序而是忽略该行如果不按顺序



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}]





有什么建议吗?



我尝试过:



i不知道如何实现这个目标。如果其中一个元素丢失,我会尝试使用ownproperty ...但这包含所有元素......但它不在一个顺序中。专家的想法请



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

推荐答案

没有必要这样做。每个数组元素都是一个具有年份和类型属性的对象,它们的顺序在这里没有问题,你可以通过它们的数组索引得到每个对象,例如
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第一个对象。要获取元素的相应属性,比如第二个元素,

for the first object. To get the respective properties of the an element, say the 2nd elements,

cars[1].type

cars[1].year

学习 JavaScript对象 [ ^ ]


这篇关于如果元素不在一个顺序中,如何忽略数组中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆