-3

When you normally wish to add a js script from a subfolder, you use: <script src=foldername/filename.js></script>

I have a specific local folder that's called jsfiles and it's placed within the same folder level as the main script calling it. But there are an unspecified number of js files with unknown names, each having one JSON files as arrays defined in it.

All files look like: var json = [{...},{...}]

How do I set up a for loop to push EACH json object in EVERY file in the jsfiles into an array, although I don't know the names to the files?

Or do I need another programming language than JavaScript for that matter?

Thanks in advance.

4
  • Yep, you can't do that, you have to generate the list of file names or include the files beforehand on the server side. Commented Sep 11, 2014 at 5:01
  • Well, you have to fetch a list from the server first. Commented Sep 11, 2014 at 5:02
  • Can you tell me how do I generate the list of filenames? Commented Sep 11, 2014 at 5:08
  • can you describe what technologies you are using on your server (ASP.NET, Ruby/Rails, PHP, etc.) so we can more accurately point you in the right direction? this is a server side process, not a client side process. Commented Sep 11, 2014 at 5:10

1 Answer 1

0

Get all the files in an array

Then:

jsArray.forEach(function(j) {
  $('head').append('<script src="...." type="..."');
});
Sign up to request clarification or add additional context in comments.

1 Comment

It's better to include the code from mentioned question in your answer. In case that question will deleted and your link become irrelevant.

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.