Blogger Information
Blog 175
fans 1
comment 0
visits 384646
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js 截取某个字符前面或者后面的字符串
dxp2tq的博客
Original
3558 people have browsed it
  1. /**
  2. * string 字符串;
  3. * str 指定字符;
  4. * split(),用于把一个字符串分割成字符串数组;
  5. * split(str)[0],读取数组中索引为0的值(第一个值),所有数组索引默认从0开始;
  6. */
  7. function getStr(string, str) {
  8. var str_before = string.split(str)[0];
  9. var str_after = string.split(str)[1];
  10. var obj = {
  11. goods: str_before,
  12. goods_id: str_after
  13. };
  14. return obj;
  15. }
  16. var s = 'GOODS#N3344520';
  17. let obj = getStr(s, '#');
  18. console.log(obj.goods)//GOODS
  19. 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!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post