Remove characters after specific character in string, then remove substring in Javascript?
javascript remove specific character from string
var newString = oldString.replaceAll("character/string goes here", "");
// Example
var oldString = "Hello World!";
var newString = oldString.replaceAll("o", "");
console.log(newString);
// Prints 'Hell Wrld!' to console.
To remove everything after a specific character in a string:
1. Call the split() method on the string, passing it the character as a parameter.
2. The split method returns an array containing two substrings, split on the provided character.
3. Access the array element at index 0 to get everything before the character.
const str = 'BMW[1996]';
const removed = str.split('[')[0];
console.log(removed); // 👉️ BMW