How to use filter() method In Javascript
Extracting the values from the JSON array by creating a new array with the filtered elements from the original existing array. filter() Method is used to create a new array from a given array consisting of only those elements from the given array that satisfy a condition set by the argument method.
Example: Using filter() method to access values.
Javascript
let jsonArrayData = [ { "Name" : "w3wiki" , "Location" : "Noida" }, { "Courses" : [ "DSA self paced course" , "DevOps Bootcamp" , "GATE prepration course" ], "Topics" : [ "Web development" , "Artifical Intelligence" , "Machine Learning" , "Data Science" , "Algorithms" ] }, ]; let filteredArrayValues = jsonArrayData .filter(item => item.Name === "w3wiki" ) console.log(filteredArrayValues); |
Output
[ { Name: 'w3wiki', Location: 'Noida' } ]
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