# Trying to create a JavaScript object/array...?

**URL:** <https://www.phphelp.com/t/trying-to-create-a-javascript-object-array/30532>\
**Category:** Javascript & Ajax\
**Created:** [November 30, 2019, 10:57am UTC](https://www.phphelp.com/t/trying-to-create-a-javascript-object-array/30532 "2019-11-30T10:57:33Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Peter1](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Peter1](https://www.phphelp.com/u/Peter1)\
**Post date:** [December 2, 2019, 9:52pm UTC](https://www.phphelp.com/t/trying-to-create-a-javascript-object-array/30532/21 "2019-12-02T21:52:48Z")

</div>

You are a master 😀

It’s a concise approach, the only thing I noticed is that it’s adding the words “text” and “value” in quotation marks which throws an error in the JavaScript side. What would you suggest for that?

---

<div class="post-metadata">

**Author:** ![astonecipher](https://www.phphelp.com/user_avatar/www.phphelp.com/astonecipher/32/2797_2.png) [@astonecipher](https://www.phphelp.com/u/astonecipher)\
**Post date:** [December 3, 2019, 12:57pm UTC](https://www.phphelp.com/t/trying-to-create-a-javascript-object-array/30532/22 "2019-12-03T12:57:27Z")

</div>

It probably means that the quotes are not actually quotes, if you copied them over.

---

<div class="post-metadata">

**Author:** ![Peter1](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/a587f6/32.png) [@Peter1](https://www.phphelp.com/u/Peter1)\
**Post date:** [December 3, 2019, 3:52pm UTC](https://www.phphelp.com/t/trying-to-create-a-javascript-object-array/30532/23 "2019-12-03T15:52:13Z")

</div>

What I meant is  
`text:`  
and  
`value:`  
cannot be surrounded in quotation marks. This will throw an error in JavaScript  
`"text":`  
`"value":`  
because it takes these as strings, not object parameters

---

<div class="post-metadata">

**Author:** ![astonecipher](https://www.phphelp.com/user_avatar/www.phphelp.com/astonecipher/32/2797_2.png) [@astonecipher](https://www.phphelp.com/u/astonecipher)\
**Post date:** [December 3, 2019, 4:03pm UTC](https://www.phphelp.com/t/trying-to-create-a-javascript-object-array/30532/24 "2019-12-03T16:03:10Z")

</div>

```auto
{
	"choices[]": {
		"Abarth": {
			"text": [
				"500"
			],
			"value": [
				1
			]
		},
		"AC": {
			"text": [
				"Cobra"
			],
			"value": [
				2
			]
		},
		"Alfa Romeo": {
			"text": [
				"4C",
				"156",
				"Brera",
				"159"
			],
			"value": [
				5,
				3,
				6,
				4
			]
		}
	}
}

```

Is valid JSON, but JavaScript still needs to parse the data to make it usable.

[https://www.w3schools.com/js/js\_json\_parse.asp](https://www.w3schools.com/js/js_json_parse.asp)

[Previous page](https://www.phphelp.com/t/trying-to-create-a-javascript-object-array/30532.md?page=1)
