How do I remove first letter from this string
d[],e[], [dsh,sj]
I get this by doing an analysis but now I need to remove first letter before every comma(,
). So,I storing it and applying for loop but it is giving me error.
*Uncaught SyntaxError: Unexpected token [*
But I am not understanding why?
EDIT : I know how to remove element but here I am not able to declare it
Expected Output : [],[],[dsh,sj]
Just to make sure we are talking about the same things:
var s = "hello"; // a String, notice the quotes
var a = [] // an empty Array
var b = ["hello", "bye"] // an Array with 2 elements
If this is your input:
var inpt = "d[],e[], [dsh,sj]";
var otpt = inpt.replace(/.\[/g,"["); // returns '[],[],[dsh,sj]' but as data type String
// this block is not very clean...
var splt = otpt.replace(/],/g, "],,");
splt = splt.split(",,");
var arr = [];
splt.forEach(function(value) {
value = value.replace(/\[|\]/g,"");
if (value === "") {
value = [];
} else {
value = value.split(",");
}
arr.push(value);
});
console.log(arr); // [[],[],["dsh","sj"]]
I would recommend to have a look at this: http://www.w3schools.com/js/default.asp
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments