I have this code
$scope.items.map(function (item) {
if(item.keywords.indexOf($scope.formData.keyword) != -1){
array.push(bono);
}
})
And I need to execute a function with all the elements of the array when the map finish. How can I do this? I thought to stack the calls but I don't know how to do it.
Thanks
The map() method returns the new array after processing each element for the given array. It accepts a callback function, which has currentItem as a mandatory parameter.
To use a map() inside a map() function in React: Call map() on the outer array, passing it a function. On each iteration, call the map() method on the other array.
How do you break a map in react JS? If you want to map() through the last N elements of an array in React, pass a negative index to the Array.To break a map() loop in React: Call the slice() method on the array to get a portion of the array. Call the map() method on the portion of the array.
map function? Not possible, We can't break #array. map, it will run for each element of array. To solve your problem, you can use slice first then map, slice first 5 elements of array then run map on that.
As soon as $scope.items
is an array as you stated in the question and the Array.prototype.map()
is synchronous - which means that you simply put the next statement after this code and it will be executed after the .map()
has completed processing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With