Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8702851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:45:14+00:00 2026-06-13T02:45:14+00:00

I have an array that’s already been instantiated in the objects class (a.k.a. prototype)

  • 0

I have an array that’s already been instantiated in the objects class (a.k.a. prototype) with new Array(), but has no data. After creating an object, I usually define its initial data all at once. Is there a way to assign all this data without doing 100 individual lines of push? Is there a way to assign a large amount of data to an existing array at once? Perhaps something like:

myArray.push([1,2,3]);

I could use:

myArray = myArray.concat([1,2,3]);

but that creates an entirely new array, which seems more expensive and messy when all I’m really doing is assigning an existing array its initial data.

Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:45:15+00:00Added an answer on June 13, 2026 at 2:45 am

    If we’re talking about an existing array, you don’t need several calls to .push(). You can pass several arguments in one call.

    myArray.push(1,2,3,4,5,6,7);
    

    If the items to be added are in a different Array, you can use .apply to add them individually.

    var itemsToAdd = [1,2,3,4,5,6,7];
    
    myArray.push.apply(myArray, itemsToAdd);
    

    But for a new Array, use either the literal syntax to create and initialize at the same time, or you can pass multiple items to the Array constructor.

    In your question you state that the Array is on the constructor’s .prototype. As I noted in the comment above, that’s usually not what you want. But if it is intended to be shared in this case, then the first two solutions above will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that is already sorted but i want to give a
I have an array that has specified colors like this, Object[] l_colarray = new
I have an array that is built using the explode() function, but seeing how
I have an array that is structured as such: $data = array( abc=>array( label
I have an array that has sequential array keys and I need to randomly
I have an array that holds numbers: int tarningar[] = new int[5]; When all
I have array that I can display by code: foreach($form->data as $key => $value){
I have an array that contains data as follows (string and time data separated
I have a two dimensional array that I need to load data into. I
I have an array that can store different types of objects. When I retrieve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.