Translating all items in an array to a new array of items using JQuery

Author: | Posted in JQuery, Learn, Uncategorized No comments

Following Example shows how to eliminate fields from an existing array to create a new array.

Consider an array as shown below;

var dimensions = [{ width: 10, height: 15, length: 20 },

                  { width: 12, height: 17, length: 22 },

                  { width: 14, height: 19, length: 24 },];

Map the needed fields to a new array of items;

var mappedDimensions = $.map(dimensions, function(obj) {

                            return {

                                width: obj.width,

                                length: obj.length

                            };

                       });

Now mappedDimensions will have the mapped items of dimensions

Add Your Comment