/**
* string 字符串;
* str 指定字符;
* split(),用于把一个字符串分割成字符串数组;
* split(str)[0],读取数组中索引为0的值(第一个值),所有数组索引默认从0开始;
*/
function getStr(string, str) {
var str_before = string.split(str)[0];
var str_after = string.split(str)[1];
var obj = {
goods: str_before,
goods_id: str_after
};
return obj;
}
var s = 'GOODS#N3344520';
let obj = getStr(s, '#');
console.log(obj.goods)//GOODS
console.log(obj.goods_id)//N3344520
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!