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

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);

原文地址:https://www.cnblogs.com/thybk/p/7278385.html