You can use a forEach like you intended if you modify the array initialization to be:
var arr = Array.apply(null, Array(10))
And then you can do a foreach like:
arr.forEach(function(el, index) {
arr[index] = 0;
});
The result is:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
More Related Contents:
- JavaScript variable with global scope [closed]
- .bind is not working with dynamic html [closed]
- jQuery Ajax File Upload
- Javascript add leading zeroes to date
- getElementsByClassName() doesn’t work in old Internet Explorers like IE6, IE7, IE8
- Error when accessing API with fetch while setting mode to ‘no-cors’ [duplicate]
- $(document).click() not working correctly on iPhone. jquery [duplicate]
- What is the temporal dead zone?
- How to set object property (of object property of..) given its string name in JavaScript?
- ToLocaleDateString() changes in IE11
- How to maintain state after a page refresh in React.js?
- Is there any way to use a numeric type as an object key?
- Boolean variable returns as string from javascript function [duplicate]
- Modifying CSS class property values on the fly with JavaScript / jQuery
- Rest with Express.js nested router
- javascript onclick event over flash object
- How can I split a string containing emoji into an array?
- How to measure the execution time of a promise?
- Smooth scroll to specific div on click
- blur event.relatedTarget returns null
- Understanding $.proxy() in jQuery
- Browser support for using a reserved word as a property name in JavaScript
- Export the HTML table to excel is not working in IE
- Curly brackets (braces) in Node.js ‘require’ statement
- Next.js context provider wrapping App component with page specific layout component giving undefined data
- Force page scroll position to top at page refresh in HTML
- ReactJS server-side rendering vs client-side rendering
- JavaScript: indexOf vs. Match when Searching Strings?
- manually trigger touch event
- Using an imported module inside Google App Script