0

Is there any way to create a List of objects in JS/JQuery as I do in C#?

I just want to dynamically add objects to a list as I do in C#. Like:

List<string> myList = new List<string>();
myList.add("myString");

Is there any way to achieve the same thing in Javascript? I don't care if the list is typed or not. I just want the data structure.

Thanks!

1 Answer 1

3

Yes, use an array.

Example:

var myList = [];
myList.push("myString");

In C# arrays are fixed size, but in Javascript you can add items to them just like lists in C#.

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

2 Comments

If you really must have a similar api you can make a wrapper for this code that has some/all of the same methods as the c# implementation which would just modify the array internally.
Thanks a ton! Simple question, simple answer.

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.