123

从字符串里提取一个列表(数组)

var santent='this is one santent. this is a santent with a list of items:'+'cherries,oranges,apples,bananas. that was the list of items.';  //创建一个字符串
var start = santent.indexOf(':');  //找到要提取列表开始位置
var end = santent.indexOf('.',start+1); //找到要提取列表的结束位置
var liststr=santent.substring(start+1,end);//通过substring提取中间的字符
var fruits=liststr.split(',');//split通过逗号分隔字符串成为数组

console.log(fruits);

posted @ 2017-08-03 10:32  thy22  阅读(877)  评论(0编辑  收藏  举报