Skip to content

JavaScript map array of objects | Example code

  • by

Using the map function you can create an array of objects. The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

JavaScript map array of objects

Simple example code.

<!DOCTYPE html>
    var arr = [{
      id: 1,
      name: 'bill'
    }, {
      id: 2,
      name: 'ted'

    var res = => ({ value:, text: }));




JavaScript map array of objects

How To Use .map() to Iterate Through Array Items in JavaScript

Answer: The map() can be used to iterate through objects in an array and, in a similar fashion to traditional arrays, modify the content of each individual object and return a new array. This modification is done based on what is returned in the callback function.

   const myUsers = [
   { name: 'Shark', likes: 'ocean' },
   { name: 'Turtle', likes: 'pond' },
   { name: 'Otter', likes: 'fish biscuits' }

   const usersByLikes = => {
    const container = {};

    container[] = item.likes;
    container.age = * 5;

    return container;



Iterate Through Array Items in JavaScript

Do comment if you have any doubts or suggestions on this JS array of objects topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading