var str="Iam a fullstack javascript developer";
var strCharArr;
[...strCharArr]=str;
var arr=strCharArr.reduce((acc, cv)=>{if(cv==" ") acc.push(""); else acc[acc.length-1]+=cv; return acc;},[""]);
console.log(arr);

[...strCharArr]=str splits the string into an array of characters.
reduce starts with an array of one element of empty string ([""]),
and either adds characters, or, in case of a space, adds an empty string element.

Answer from iAmOren on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › string-to-array-in-javascript
JavaScript - Convert String to Array - GeeksforGeeks
August 5, 2025 - Strings in JavaScript are immutable (cannot be changed directly). However, arrays are mutable, allowing you to perform operations such as adding, removing, or modifying elements. Converting a string to an array makes it easier to: Access individual characters or substrings. Perform array operations such as map, filter, or reduce. Modify parts of the string (like replacing characters or extracting substrings). Split a string into smaller components for easier processing.
🌐
ReqBin
reqbin.com › code › javascript › jaarxzpl › javascript-string-to-array-example
How do I convert string to array in JavaScript?
The Array.from() method in JavaScript is used to create an array from any iterable object. The from() method returns a new array instance whose elements correspond to each element in the iterable.
🌐
Medium
medium.com › @jsomineni › 3-ways-to-convert-string-into-array-in-javascript-3eacfc729cf6
3 ways to convert String into Array in JavaScript | by Jayanth babu S | Medium
September 1, 2024 - 3 ways to convert String into Array in JavaScript Introduction Converting a string into an array is a common task in JavaScript, especially when you need to manipulate or access individual characters …
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
How to convert string and operation chars to array? - JavaScript - The freeCodeCamp Forum
January 28, 2022 - let myInput = 2-5+(3*2) How can we convert it to myinputArray = [ "2", "-", "5", "+", "(", "3", "x", "2", ")" ]
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › convert-string-to-array
Convert a String to an Array in JavaScript
The `trim` option in Mongoose schema definitions makes Mongoose automatically call `String.prototype.trim()` on string fields. Here's how it works. ... Here's how JavaScript arrays' `flatMap()` method works, and what you can use it for.. ... Here's how you can use ES6 Sets to get distinct values in an array. ... Here's how Mocha's afterEach() hook works. ... Got a JavaScript date that is showing up as "Invalid Date" in your console? Here's how you check for that. ... Here's how you can use the btoa() function in JavaScript to convert strings to base64.
🌐
Reddit
reddit.com › r/javascripttips › how to turn string into array in javascript
How to Turn String into Array in JavaScript : r/JavaScriptTips
December 11, 2022 - 19K subscribers in the JavaScriptTips community. A place to get a quick fix of JavaScript tips and tricks to make you a better Developer.
🌐
DEV Community
dev.to › sanchithasr › 6-ways-to-convert-a-string-to-an-array-in-javascript-1cjg
6 Ways to Convert a String to an Array in JavaScript - DEV Community
September 24, 2022 - https://stackoverflow.com/questions/96428/how-do-i-split-a-string-breaking-at-a-particular-character · https://stackoverflow.com/questions/4547609/how-to-get-character-array-from-a-string/34717402#34717402 · https://www.stevenchang.tw/blog/2020/05/23/JavaScript-slice-call-function ... To sum it all up, below are the ways we can do the job. That’s 6 ways to convert string to array in JavaScript.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › from
Array.from() - JavaScript | MDN
A new Array instance. ... To convert an ordinary object that's not iterable or array-like to an array (by enumerating its property keys, values, or both), use Object.keys(), Object.values(), or Object.entries().
🌐
Quora
quora.com › How-do-I-convert-string-to-array-without-using-split
How to convert string to array without using split() - Quora
Answer (1 of 4): What language are you asking about? You tagged the question with “C (programming language)”, but C does not have a [code ]split()[/code] function — although it does have [code ]strtok()[/code] which accomplishes almost the same thing.
🌐
SamanthaMing
samanthaming.com › tidbits › 83-4-ways-to-convert-string-to-character-array
4 Ways to Convert String to Character Array in JavaScript | SamanthaMing.com
It seems that browsers have some kind of mechanism in place to "safely" do Object.assign([], "string") and avoid adding the methods of that string to the array.
🌐
W3Schools
w3schools.com › jsref › jsref_tostring_array.asp
JavaScript Array toString() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
Attacomsian
attacomsian.com › blog › javascript-convert-string-to-array
How to convert a string to an array in JavaScript
August 12, 2022 - A quick article to learn about 4 different ways to convert a string into an array in vanilla JavaScript.
Top answer
1 of 3
1

String manipulation should be the last resort.

[{'Id':'01t6700000Cwxot','Name':'Product1'}, {'Id':'01t6700000CwxjY','Name':'Product2'}]

If the desired output is this one, the task would be a lot easier if you define an array then push several object. You need an array (could be selSpot) and several object with two properties: Id and Name. You can build those object each time a user select the spot:

selSpot = [];

yourMethod() {
    // something

    // Define the new object
    const clickedSpot = {
        Id: this.record.prod_id__c,
        Name: this.record.prod_name__c
    };
    this.selSpot.push(clickedSpot);

    // pass the array to the parent
    const selectedSpotEvent = new CustomEvent('meaningfulEventName', { detail: { selectedSpot: this.selSpot.map((elem) => ({...elem})) });
    this.dispatchEvent(selectedSpotEvent);
}

Keep in mind that Javascript is case-sensitive, so id and Id are not the same.
Note that I deep cloned the array before passing it to the parent, this way the parent component cannot mutate the one of the child, nor its elements.
Documentation (emphasis mine)

JavaScript passes all data types by reference except for primitives.
If a component includes an object in its detail property, any listener can mutate that object without the component’s knowledge. This is a bad thing!
It’s a best practice either to send only primitives, or to copy data to a new object before adding it to the detail property.
Copying the data to a new object ensures that you’re sending only the data you want, and that the receiver can’t mutate your data.

Please use meaningful names for variables, calling an array testmap may confuse others

2 of 3
0

Instead of using a string, you can populate a list directly using push. For example:

this.clickedAddSpot = [];
this.clickedAddSpot.push("{'id':'"+this.record.prod_id__c+"','Name':'"+this.record.prod_name__c+"'}");
🌐
Codedamn
codedamn.com › news › javascript
How to convert a string to an Array in JavaScript?
November 14, 2022 - Hey readers, In this article we will discuss various ways in which we can convert a string to an array. Let’s get started without any further delay. In any programming language, a string generally represents a group of characters. A string is nothing but text. The primitive data types of javascript are string, undefined, symbol, number, bigint, boolean and null.
🌐
Stack Abuse
stackabuse.com › how-to-convert-a-string-to-an-array-in-javascript
How to Convert a String to an Array in JavaScript
May 22, 2023 - Whether you're breaking a word down into its characters, or a sentence into words - splitting a string into an array isn't an uncommon operation, and most languages have built-in methods for this task. In this guide, learn how to convert a String to an Array in JavaScript, with the split(), ...
🌐
C# Corner
c-sharpcorner.com › article › convert-string-into-array-in-javascript
Convert String into Array in JavaScript
August 21, 2023 - If you prefer not to use the split() method, you can manually convert a string into an array using a loop: const sentence = "JavaScript runs everywhere on everything!"; const words = []; let currentWord = ""; for (let index = 0; index < ...
🌐
Reddit
reddit.com › r/nextjs › converting a string array into an array
r/nextjs on Reddit: Converting a String Array into an Array
August 4, 2023 -

So im trying to convert an array that was turned into a string from DynoDB. I got it formatted properly but I cant get it to work. (Incase you are wondering what this is for, its for a log keeping track of changes to a db. This is just showing the string with its state)

Here is the string:
"{PK:PHOTO01H70M6DC9YW6KPJBF15DQKDBF, SK:PHOTO01H70M6DC9YW6KPJBF15DQKDBF, type:photo, date:2023-08-02, dateRangeStart:null, dateRangeEnd:null, year:2023, featured:null, title:Title test, description:Adfsdf, linkAddress:null, location:Alberta, tags:[], people:[Free Press, School Division], bucket:bucket, region:null, key:null, filename:Screenshot 2023-07-19 at 13-44-34 Admin Add Files.png, filedesc:null, dateSK:2023-08-02#dodeyby, uploadedBy:deathbyunknown, createdAt:2023-08-04T15:55:54.644Z, updatedAt:2023-08-04T15:58:20.579Z}"

Things I've tried:
Convert using Object.entrys(), Result is an array with all the characters as a single item in the array.
JSON.parse(), Result error message: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data.

EDIT: Santizied Information that shouldn't be shown

🌐
Shovon Hasan
blog.shovonhasan.com › never-use-array-from-to-convert-strings-to-arrays
Never Use Array.from() to Convert Strings to Arrays
July 27, 2019 - Never use Array.from() to convert a string of any length to an array. Instead, prefer String.prototype.split. The 2016 ECMAScript spec for String.prototype.split and 2016 ECMAScript spec for Array.from are available here. Someone with a deeper understanding of JavaScript can probably do a much better job than I at explaining the performance disparity.