-2

data array variable contains big number of data, And i have some of StartIndex and EndIndex, I need only those data which are in between startIndex and EndEndex.

Is there any method which can help to get data in from start index to EndEndex without using for loop.

StartIndex and EndIndex are dynamic which can change any time while running web page.

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)

3
  • 1
    use Array.filter() to accomplish what you need Commented Nov 21, 2018 at 12:05
  • 2
    You can user array.slice(start, end) to break the array Commented Nov 21, 2018 at 12:06
  • working with array.slice(start, end) Commented Nov 21, 2018 at 12:18

1 Answer 1

1

Use slice method of an array. An Example

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.