How to Convert Array Into Object In Jquery?
Hi Guys,
In this example,I will learn you how to convert array into object in jquery.you can easy and simply convert array into object in jquery.
We will use Object.assign() for converting array into json object using jquery. we have to just pass object as argument in Object.assign().let's bellow example.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Jquery Array to Object Convert - Nicesnippets.com</title>
</head>
<body>
<script>
var myArray = [
'apple',
'banana',
'orange',
'mango',
'pineapple'
];
var myObject = Object.assign({}, myArray);
console.log(myObject);
</script>
</body>
</html>
Output:
{0: "apple", 1: "banana", 2: "orange", 3: "mango", 4: "pineapple"}
0: "apple"
1: "banana"
2: "orange"
3: "mango"
4: "pineapple"
It will help you...
- How to Show Loading Spinner in JQuery?
- How to Create Ajax Submit Form Using jQuery?
- How To Get Current Page URL, Path, Host and hash using jQuery?
- How To Get, Set and Delete Div Background Image jQuery?
- JQuery Remove All Unwanted Whitespace From String Example
- Body Background Video Using Vide Jquery Example
- JQuery UI Autocomplete Example
- JQuery Split String By Comma Into Array Example