0

If I have the following string: table.row.columns.values.many. I am looking to add character * after values. So expected output would be: table.row.columns.values*.many . If there is no "values" in string then string should stay the same.

4
  • So, what have you tried to achieve this ? Can you show us ? Commented Aug 18, 2021 at 12:35
  • 1
    Use replace? It’s unclear what the specific issue is since this should be easy to search for. Commented Aug 18, 2021 at 12:35
  • 1
    Yeah I can test for "values" and replace it with "values*" but idk if that is right Commented Aug 18, 2021 at 12:37
  • @GurbazPooran It’s right if it works. This is easy to test in a console or NodeJS REPL (console). Commented Aug 18, 2021 at 12:45

2 Answers 2

1

Please use this code.

let str = "table.row.columns.values.many"
str = str.replace("values", "values*");
console.log(str);

You can use also "replaceAll" if you want to replace all "values".

Sign up to request clarification or add additional context in comments.

Comments

0

I think this works nice for you, really simple, and easy way

var str = "table.row.columns.values.many";
str = str.replace("values", "values*")

console.log(str)

2 Comments

this doesn't work. replace returns another string. If you want to change the original string you need to assign the 'replace' string to the initial string. str = str.replace(....)
Yeah, now i've did some changes on the code, but nevermind, the right answer is on the top...

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.