0

I'm trying to get the data in an array in javascript.

here's my arrayProgram in javascript:

    [0] => Array (
    [Program] => Array (
        [event_name] => Event Daily
        [keyword] => KVIP SHOWTIME
        [start_date] => 2017-04-07 12:00:00
        [end_date] => 2017-04-03 15:00:00
        [location] => Studio 1
        [slots] => 10
        [event_color] => #9a9aff
        [is_allday] => 1
        [repeat_program] => daily-weekly
        [repeat_every] => 1
        [repeat_days] => ,1,2,3,4,5,6
        [repeat_yearly] => 0
        [is_end] => 0
        )
    )
[1] => Array (
    [Program] => Array (
        [event_name] => NEWS
        [keyword] => KVIP NEWS
        [start_date] => 2017-04-30 05:30:00
        [end_date] => 2017-04-01 19:00:00
        [location] => Studio 4
        [slots] => 05
        [event_color] => #fb8979
        [is_allday] => 1
        [repeat_program] => monthly
        [repeat_every] => 0
        [repeat_days] => 
        )
    )
[2] => Array (
    [Program] => Array (
        [event_name] => ASAP
        [keyword] => KVIP ASAP
        [start_date] => 2017-12-31 12:00:00
        [end_date] => 2017-04-01 15:00:00
        [location] => Studio 10
        [slots] => 16
        [event_color] => #9a9aff
        [is_allday] => 1
        [repeat_program] => yearly
        [repeat_every] => 0
        [repeat_days] => 
        )
    )

how can I extract the data using a for loop? I tried using $.each but it doesn't work for me. Can someone please help me?

1 Answer 1

1

You can loop by using for statement:

var arr = [/* your array data here*/];

for (var i = 0; i < arr.length; i++)
{
    console.log( arr[i]['Program']['event_name'] );
    console.log( arr[i]['Program']['keyword'] );
    // ... use arr[i]['Program'][...] to access other attribute
}
Sign up to request clarification or add additional context in comments.

Comments

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.