0

here's my code.

    jQuery('#delete_item').click(function(){
        var arr = array();
        jQuery('.man_id:checked').each(function (){
            var value = jQuery(this).val();
            arr += value;
        });
        alert(arr);

    });

what I want is to store all the value in the array.. is it possible?

4 Answers 4

4

Mistake 1: Actually you declare array() is wrong there two methods to declare array in javascript

1) var arr = new Array();

2) var arr = [];

Mistake 2: You have concanate the array but actually we have use push() method to insert array in javascript. Pushing array with two methods I given below

 1) arr.push(value);
 2) arr[index] = value;

your code be

jQuery('#delete_item').click(function(){
        var arr = [];
        jQuery('.man_id:checked').each(function (){
            var value = jQuery(this).val();
            arr.push(value);
        });
        alert(arr);

    });
Sign up to request clarification or add additional context in comments.

1 Comment

ty sir.. you are a great help. =)
1

You can use jQuery.map() to get the array. Using this.value will be more efficient then use jQuery(this).val();

jQuery('#delete_item').click(function(){
    var arr = jQuery('.man_id:checked').map(function(){
        return this.value;
    }).get();
});

Comments

1

You can use .map()

jQuery('#delete_item').click(function () {
    var arr = jQuery('.man_id:checked').map(function () {
        return this.value
    }).get();
    alert(arr);
});

Comments

1

Use map() in jquery .Translate all items in an array

  var arr = $('.man_id:checked').map(function (){
             return this.value;
        }).get();
        alert(arr);

3 Comments

@downvoter Please put your comment for your downvote, without comment it would't change anything here
@NorlihazmeyGhazali ennada enna ?
@Bala - You have to improve your communication skill da .

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.