0

First I declare my array as

var Ulturls = [];

and if try to push an object

 var p ={'url' :'https://someurl.com', 'name':'someName', 'id': 'adast'}
 Ulturls.data.push(p)

I need to use push since I want my array to looks like this

Ulturls = [
    'data': [
               {
                 "name": "Usain Bolt is the real bro_video.mp4",
                 "url": "https://v.redd.it/l1yuug6bcc551/DASH_480",
                 "id": "cln8vskbjlbozk"
               },
               {
                 "name": "Usain Bolt is the real bro_audio.mp3",
                 "url": "https://v.redd.it/l1yuug6bcc551/audio",
                 "id": "cln8vskbjlbozl"
               }
          ]
     'total': 2
 ]
3
  • Whats your question? Commented Jun 17, 2020 at 17:51
  • You should use an object instead of an array for Ulturls, as the keys of arrays are always indexes. Commented Jun 17, 2020 at 17:55
  • 1
    There is no JSON in your code. A JavaScript object is not JSON. Commented Jun 17, 2020 at 17:56

1 Answer 1

1

This isn't valid syntax:

Ulturls = [
    'data': [...]
    'total': 2
 ]

What I think you're looking for is an object, not an array. Try this:

var Ulturls = {
    data: []
}
Ulturls.data.push({
    "name": "Usain Bolt is the real bro_video.mp4",
    "url": "https://v.redd.it/l1yuug6bcc551/DASH_480",
    "id": "cln8vskbjlbozk"
});
Ulturls.data.push({
    "name": "Usain Bolt is the real bro_audio.mp3",
    "url": "https://v.redd.it/l1yuug6bcc551/audio",
    "id": "cln8vskbjlbozl"
});
Ulturls.total = Ulturls.data.length;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I'll try your suggestion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.