I have an Array of Objects
var array = [ {type: 'news', id: 1}, {type: 'contacts', id: 7}, {type: 'messages', id: 11} ]
I need a decision that I can add a property and value to an Object. Which to define which object to add a property to, I have a type
Something like
function(arr = array, type = 'news', property = 'visibility ', value = 'yes') {
var obj = arr.find(item => item.type === type)
/* magic */
return result
}
result = [ {type: 'news', id: 1, visibility: 'yes'}, {type: 'contacts', id: 7}, {type: 'messages', id: 11} ]