Hello so I'm wondering if I have a string like this
var string = '"In Another World" "Magic Books"'
how can I make an array every that contains every name in the [""]??
the result that I want:
an array named 'Array' that contains every name from the string
an error that appears if the ["] has no second ["]
for an example:
var string = '"example'
it will return an error
and if there is no [""] it will make an array that contain string value
Try this:
string = '"In Another World" "Magic Books"';
const tempArr = string.split('"');
const filteredArr = tempArr.filter(function (el) {
return el != null;
});
console.log(filteredArr)
You should not use "
this a marker or split point as both '
and "
represents string so its better to use any other symbols or character like *
or :
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.