0
for (var i = 0; i < input.files.length; ++i) {
     name = name.push(input.files[i].name)
}

I want to get the name of the files and put them in a array so I can post them to a php file to upload. Please help.

The variable name is the array I want to post.

is there a loop in javascript like foreach in php

3
  • so what's the problem in this? Commented Jun 26, 2012 at 8:19
  • What is the question / problem you are having? Commented Jun 26, 2012 at 8:19
  • i want to upload files using jquery and php Commented Jun 26, 2012 at 9:53

3 Answers 3

4

How about this:

var name = [];
for (var i = 0; i < input.files.length; ++i) {
     name.push(input.files[i].name);
}
Sign up to request clarification or add additional context in comments.

2 Comments

it doesn't give an array after the loop
name is your array - you add the values inside name and later you can iterate over it.
1

Try it this way

var name = new Array();

for (var i = 0; i < input.files.length; ++i) {
   name[i] = name.push(input.files[i].name)
}

1 Comment

I think you meant name[i] = inputfiles[i].name;
0

I found the answer the code uses both for loop and jquery $.each loop Thanx

for (var i = 0; i < input.files.length; ++i) {
   $.each(input.files.name,function(index,value){
     if(index == 'name'){
       name.push(value)
     }
   })
}

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.