Remove square brackets at beginning and ending using Undersore or Javascript

拥有回忆 提交于 2019-12-11 19:02:02

问题


I trying to remove array square bracket at beginning and end.

EX: [['moe', 30], ['larry', 40], ['curly', 50]]

Need: ['moe', 30], ['larry', 40], ['curly', 50]


回答1:


If it is a string you can use the substring or slice method like this:

var yourString = "[['moe', 30], ['larry', 40], ['curly', 50]]";
// using substring
var result = yourString.substring(1, yourString.length-1);
console.log(result);
// using slice
var result2 = yourString.slice(1, -1);
console.log(result2);


来源:https://stackoverflow.com/questions/49895931/remove-square-brackets-at-beginning-and-ending-using-undersore-or-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!