Daniel Makinbo
Daniel Makinbo

Reputation: 59

Converting javascript array into individual variables using jQuery

I am trying to explode an array into individual variables which I can then post to my PHP file using $.ajax.

My array is as follows:

var arr = ["11th", "february", "2013"]

// How can I go through this array and take each element and place it into its individual variable?

Upvotes: 0

Views: 279

Answers (1)

MatRt
MatRt

Reputation: 3534

You can directly use your array for posting data

when you do your post in ajax, you can send different var and so, send separately arr[0], arr[1] and arr[2]. You can do this by writting this in the configuration of your ajax post:

$.ajax({
    ..your config..,
    data: { 
        day: arr[0], 
        month: arr[1], 
        year: arr[2] 
    },
    ...your config...
});

Upvotes: 1

Related Questions