Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Array.prototype.fill() with object passes reference and not new instance in JavaScript?
To fix this, you can use map() in JavaScript.
The syntax is as follows −
var anyVariableName= new Array(yourSize).fill().map(Object);
Example
Following is the code −
var arrayOfObject = new Array(5).fill().map(Object); console.log(arrayOfObject);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo311.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo311.js
[ {}, {}, {}, {}, {} ] Advertisements
