javascript - quoting individual characters(words) in a string on java script -


learner here, bear me if question seems absurd. trying quote characters in string , not string itself, how go doing that? mean is;

given: var str = "i wondered scattered brained computer remain sane"

and want :

var output read = ""i" "wonder" "what" "a" "scattered" "brained" "computer" "does" "to" "remain" "sane""

what think best action take?

you can reach desired solution string#replace, wrap each single word in quotation marks ".

const str = 'i wondered scattered brained computer remain sane';    let res = str.replace(/\w+/g, '"$&"');    console.log(res);


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -