10 examples of 'convert json to array in jquery' in JavaScript

Every line of 'convert json to array in jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
42function translateArraysToJSON(keys, value) {
43 const MyJSON = {};
44 let index = 0;
45 for (const item of keys) {
46 const currentKeys = item.split(".");
47 let currentKey = "";
48 for (let el of currentKeys) {
49 currentKey += `["` + el + `"]`;
50 if (!eval("MyJSON" + currentKey)) {
51 eval("MyJSON" + currentKey + "={}");
52 }
53 }
54 eval("MyJSON" + currentKey + "=" + "`" + value[index++] + "`");
55 }
56 return MyJSON;
57}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

10function convertToObject (array) {
11 const obj = []
12 array.forEach((element, index, array) => {
13 obj[element[0]] = element[1]
14 })
15 return obj
16}
77function jsonToArray(p_name)
78{
79 var array = [];
80 var jsonArray = json.get(p_name);
81 for (var i = 0, j = jsonArray.length(); i < j; i++)
82 {
83 array.push(jsonArray.get(i));
84 }
85 return array;
86}
26export function parseJson(json) {
27 return JSON.parse(json, function (k, v) {
28 if (v.indexOf && v.indexOf('function') > -1) {
29 try {
30 return eval('(function(){return ' + v + ' })()')
31 } catch (e) {
32 console.error(`[form-create]解析失败:${v}`);
33 return undefined;
34 }
35 }
36 return v;
37 });
38}
111export function parseJson(json) {
112 return /** @type {?JsonObject} */ (JSON.parse(/** @type {string} */ (json)));
113}
3function convertStringToArray(string) {
4 let array = [];
5 try {
6 array = JSON.parse(string);
7 } catch (err) {
8 // Assume is just a string (single url)
9 if (string) {
10 array = [string];
11 }
12 }
13 return array;
14}
1export function makeArray(value) {
2 return Array.isArray(value) ? value : value ? [value] : [];
3}
15function arrayParser(json) {
16 var result = '[';
17 for(var i=0;i<json.length;i++) {
18 var type = Object.prototype.toString.call(json[i]);
19 if(type == ARRAY_STR) {
20 result += arrayParser(json[i]);
21 }
22 else if(type == OBJECT_STR) {
23 result += objectParser(json[i]);
24 }
25 else if(type == STRING_STR) {
26 result += '"'+json[i]+'"';
27 }
28 else {
29 result += json[i];
30 }
31 if(i < (json.length-1)) {
32 result += ',';
33 }
34 }
35 result += ']';
36 return result;
37}
97function convertToArray(object) {
98 if (Object.prototype.toString.call( object ) === '[object Object]' ) {
99 var array = [];
100 array.push(object)
101 return array;
102 }
103 else {
104 if( Object.prototype.toString.call( object ) === '[object Array]' ) {
105 return object;
106 }
107 }
108}
6function arrayify (o) {
7 if (Array.isArray(o)) {
8 return o
9 } else {
10 return [o]
11 }
12}

Related snippets