Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Js – create new array with the last two letters in string from previous array

I would like to loop through and array and then get the last two letters from each string and create a new array with them?

my current array is

myArray = [Qe3,Ke4,Qe5,Je6]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I would like to end up with this

newArray = [e3,e4,e5,e6]

this is for www.chessonline.app

>Solution :

Use slice


const newArray = myArray.map(str => str.slice(-2)); // Use map() to apply a function to each element of the array
// The function uses slice() to return the last two characters of each string

console.log(newArray); // ['e3', 'e4', 'e5', 'e6']


Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading