Answers for "how to get the next item in map() js"

0

how to get the next item in map() js

// The callback of map method accepts 3 arguments:

// current item value;
// current item index;
// the array map was called upon.
// So, you could use index to get next element value:

var newArray  = myArray.map(function(value, index, elements) {
  var next = elements[index+1];
  // do something
});
Posted by: Guest on June-29-2020

Code answers related to "how to get the next item in map() js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language