Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
93 views
in Technique[技术] by (71.8m points)

javascript - Convert a string to an array without splitting it

Is it somehow possible to convert a string to an array as easy as possible without any hacks? and without splitting the string at some point?

For example bringing this:

temp = 'Text';

to this:

temp = ['Text'];

It might be a simple question but I couldn't find any solution without splitting the string.

question from:https://stackoverflow.com/questions/65850219/convert-a-string-to-an-array-without-splitting-it

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want an array with the string as a single value just create a new array with that string.

temp = [temp]; 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...