enter image description hereI need to insert a file object at specific index like:1,5,6 in an empty array using angularJs. I want result something like given in the following attached image
1 Answer
You can just use the [n] notation.
const myArray = []
myArray[1] = 'something'
myArray[5] = 'inserted'
myArray[6] = 'in array'
console.log('myArray ', myArray)
Although I would recommend using javascript object if you need to work with custom property names.
Then you would do something like this:
const myObject = {}
myObject[1] = 'first file'
myObject[5] = 'second file'
myObject[6] = 'third file'
and you can always iterate through that object like this:
Object.keys(myObject).forEach(propertyName => console.log('property name ', propertyName, ' property value ', myObject[propertyName]));
