数据数组变量包含大量数据,并且我有一些StartIndex和EndIndex,我只需要那些介于startIndex和EndEndex之间的数据。
有没有什么方法可以帮助从起始索引到EndEndex获取数据,而无需使用for循环。
StartIndex和EndIndex是动态的,可以在运行网页时随时更改。
var data=[
{
"ID": "1783603",
"LongDescription": "this is long desc.",
"ShortDescription": "This is long desc",
"Name": "Name Field"
},
{
"ID": "1783604",
"LongDescription": "this is long desc.",
"ShortDescription": "This is long desc",
"Name": "Name Field"
},
{
"ID": "1783605",
"LongDescription": "this is long desc.",
"ShortDescription": "This is long desc",
"Name": "Name Field"
},
{
"ID": "1783606",
"LongDescription": "this is long desc.",
"ShortDescription": "This is long desc",
"Name": "Name Field"
},
{
"ID": "1783607",
"LongDescription": "this is long desc.",
"ShortDescription": "This is long desc",
"Name": "Name Field"
},
{
"ID": "1783608",
"LongDescription": "this is long desc.",
"ShortDescription": "This is long desc",
"Name": "Name Field"
},
{
"ID": "1783609",
"LongDescription": "this is long desc.",
"ShortDescription": "This is long desc",
"Name": "Name Field"
},
{
"ID": "1783610",
"LongDescription": "this is long desc.",
"ShortDescription": "This is long desc",
"Name": "Name Field"
},
{
"ID": "1783611",
"LongDescription": "this is long desc.",
"ShortDescription": "This is long desc",
"Name": "Name Field"
}
]
console.log(data)
var FromIndex=2;
var EndIndex=5;
var ResultArray=[];
for(var i=FromIndex;i<=EndIndex;i++){
ResultArray.push(data[i])
}
console.log(ResultArray)