我有以下字符串:'#d48888,abc.com,repeat,top left,scroll';

如何将该字符串转换为如下数组:Array('color'=>#d48888, 'href'=>abc.com, ... )

最佳答案

尝试这个,

首先以逗号分割字符串:

var string = '#d48888,abc.com,repeat,top left,scroll';
var arrayOfString =   str.split(',');


使用另一个数组存储键=>值对:

var newArray = {};
newArray.color = arrayOfString[0];
newArray.href = arrayOfString[1];
newArray.action = arrayOfString[2];
newArray.top = arrayOfString[3];
newArray.scroll = arrayOfString[4];

08-15 16:20