How to use forEach() In Javascript
Extracting values from the JSON arrays by executing a function for each element of the array. forEach() method calls the provided function once for each element of the array. The provided function may perform any kind of operation on the elements of the given array.
Example: Using for Each() method to access values.
Javascript
let jsonArrayData = [ { "ComapnyName" : "w3wiki" , "Location" : "Noida" }, { "Courses" : [ "DSA self paced course" , "DevOps Boot camp" , "GATE prepration course" ], "Topics" :[ "Web Devlopment" , "Machine Learning" , "Artifical Intelligence" ] } ]; jsonArrayData.forEach( function (element){ console.log(element); }); |
Output
{ ComapnyName: 'w3wiki', Location: 'Noida' } { Courses: [ 'DSA self paced course', 'DevOps Boot camp', 'GATE prepration course' ], Topics: [ 'Web Devlopment', 'Machine Learnin...
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