M
M
Messi2018-08-14 18:10:17
Yii
Messi, 2018-08-14 18:10:17

How to remove keys?

Hello! Tell me, please:
When, for example, the method returns data in the form of json.
I will always have an array like this:
id: 0
type: 'car'
How can I pass it to js like this? Now it comes in this:
{id:0, type: 'car'}

[
  { id: 0, type: 'car'},
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-08-20
@FitTech

It's simple:
{id:0, type: 'car'}is the passed single object.
[ { id: 0, type: 'car'} ]is the passed array of objects.
If you want to pass an object, pass json_encode(Object).
If you want to pass an array, pass json_encode([Object1, Object2]).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question