How to use the map() method In Javascript
Accessing values from the JSON array by creating a new modified array from the existing JSON array values. map() method creates an array by calling a specific function on each element present in the parent array. It is a non-mutating method.
Example: Using map() method to access value.
Javascript
let jsonArray = [ { "ComapnyName" : "w3wiki" , "Location" : "Noida" }, { "Courses" : [ "DSA self paced course" , "DevOps Boot camp" , "GATE prepration course" ], "Topics" : [ "Web Devlopment" , "Machine Learning" , "Artifical Intelligence" , "Data Science" ] } ]; let modifiedArray = jsonArray.map((item) => { return item.ComapnyName ? item.ComapnyName.toUpperCase() : item.Courses.join( ", " ); }); console.log(modifiedArray); |
Output
[ 'w3wiki', 'DSA self paced course, DevOps Boot camp, GATE prepration course' ]
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