How to use the array.slice method In Javascript
Extracting JSON arrays portion of values using slice method. slice() method returns a new array containing a portion of the array on which it is implemented. The original remains unchanged.
Example: Using the slice method to access values.
Javascript
let fruitsJsonArray = [ "Kiwi" , "Apple" , "Mango" , "Guava" , "Dates" ]; let slicedJsonArray = fruitsJsonArray.slice(1, 5); console.log(slicedJsonArray); |
Output
[ 'Apple', 'Mango', 'Guava', 'Dates' ]
How to Get a Value from a JSON Array in JavaScript ?
We are going to iterate or access the value of a JSON array in JavaScript. There are several ways and techniques to access values from the JSON Array which are explained in detail below and are further divided into several possible techniques.
Table of Content
- Using the array[index] method
- Using the array[key] method
- Using the array.slice method
- Using for…of the loop
- Using forEach()
- Using the map() method
- Using filter() method
- Using the find() method
- Using findIndex() method
- Using some() method
- Using recursive traversal of JSON array
- Using the custom reduce method
- Using custom classes
Contact Us