Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have an array with strings in which I want to remove the last character. How can I make it possible to remove the last character for all strings that I have in the array?
use a .map() to get a new array and for each item do a .slice(0,-1) to remove the last char.
.map()
.slice(0,-1)
const array = ['abcd', '1234', 'cde', 'dot.'] const withoutLastChar = array.map(string => string.slice(0, -1)); console.log(withoutLastChar);
Add a comment
you can used this way
const array = ['ab', 'aabb', 'ba', 'bbaa']; const removingLastChar = array.map(string => string.substring(0, string.length - 1)); console.log({ removingLastChar });
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.