Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

nodejs add new property array object

const data = [{ name: 'dendi', age: 23 }, { name: 'dhani' }]
const result = data.filter((v, i) => {
	if (!Object.keys(v).includes('age')) {
		Object.defineProperty(v, 'age', {
			value: 25,
			writeable: true,
			enumerable: true
		})
	}
	return v
})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #nodejs #add #property #array #object
ADD COMMENT
Topic
Name
6+6 =