My array contains values in the form of a comma as a separator, such as
array = {Raju, Rani, Raghu, Shiva, Stephen, Varam}. But I want to convert to format like
array = {Raju: Rani Raghu: Shiv etephen: warm}. Please make some arguments to implement it.
If you are starting with a string, you can split it on a comma: < / P>
var myString = 'Raju, Rani, Raghu, Shiva, Stephen, Warm'; Var array = myString.split (','); In view of this, you can do the following:
var array = ['Raju', 'Rani', 'Raghu', 'Shiva' , 'Stephen', 'Warm']; Var result = {}; For (var i = 0; i & lt; array.length; i + = 2) {Results [array [i]] = array [i + 1]; } ... which gives you the requested response.
Keep in mind that if the array is not divided by 2, then the value of the last item will be undefined .
Comments
Post a Comment