I don’t understand how to replace one character with another in an array. For example: we have an object that is output by array as an array, for example:

var obj = {Alphabet : [Aa], [Bb], [Cc]} var res = []; for (var key in obj) { res.push(key + ': ' + obj[key]); } console.log(res) // ["Alphabet: Aa,Bb,Cc"] 

I cannot use the replace method (this is a string method, not an array). It is necessary to obtain:

 ["Alphabet: Aa, Bb, Cc"] 

Thanks in advance for your help!

  • Do you need spaces? - Netahaki
  • @Netahaki yep so the spaces appear - Alex Lynch

1 answer 1

 var obj = { Alphabet: ['Aa', 'Bb', 'Cc'] }; var objLength = obj.Alphabet.length; for (var i = 1; i < objLength; i++) { obj.Alphabet[i] = (' ' + obj.Alphabet[i]); } var res = []; for (var key in obj) { res.push(key + ': ' + obj[key]); } console.log(res);