score:0

use simple js:

let str = "12345 12345 54321",
    len = str.length - 1,
    newstr = "",
    i = 0;

while (i != 5) {
    newstr = str[len] + newstr;
    len--; i++;
}

console.log(newstr)

score:0

you can use fill function too :

let arr = "123451234554321".split("");
 arr = arr.fill("*" , 0 , 10).join("");


console.log(res);

and the output is :

**********54321

score:1

for string use -

{this.props.x ? (
          <p>
            card number: <br />
            {"***** *****" + this.props.x.slice(-5)}
          </p>
        ) : (
          ""
        )
}

for number use -

{this.props.x ? (
          <p>
            card number: <br />
            {"***** *****" + this.props.x%100000}
          </p>
        ) : (
          ""
        )
}

hope this helps!

score:1

maybe try turning into a string so you can use the substr method.

const string = this.props.x.tostring()
const lastfive = string.substr(string.length - 5);

hope this helps.

score:2

if x is a (whole) number then it can't have space and your all 15 digit will be together. in that case you can use something like

{"***** *****" + (this.props.x % 100000)}

and if it is a string like you mentioned in your question with spaces after every 5 characters then you can use array.prototype.slice()

{"***** *****" + (this.props.x.slice(12)}

Related Query

More Query from same tag