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

  • SEARCH
  • Home
  • 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 8723505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:38:42+00:00 2026-06-13T07:38:42+00:00

How to set the value of an array from a function? The issue is

  • 0

How to set the value of an array from a function?
The issue is because I’ve to change the value of the index before of be set with an variable value.

function foo(arr) {
    this.arr=arr;
}

var f = new foo(['a', 'b', 'c']);

// I had thinked in use a function like this one
// Note thta I used index to pass an array wich could
// be greater than 1 dimension.

foo.prototype.setv = function(index, v) {
    this.arr.index = v;
}

// but it does not works like I was expecting
idx = [1];
foo.setv(idx, "Z");
  • 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-13T07:38:44+00:00Added an answer on June 13, 2026 at 7:38 am

    This:

    this.arr.index = v;
    

    Should be this:

    this.arr[index] = v;
    

    In your code you are setting a property of the array, named “index” to a value. This does not actually use the index argument passed to your setter function. Using the braket notation for setting allows you to use the index argument as an actual index for the array.

    But also, your expected usage is strange:

    idx = [1];
    foo.setv(idx, "Z");
    

    Why is idx an array? If you want to set a specific index of the internal array to a value, you would expect to pass in just the index. So that would make more sense to be simply:

    idx = 1;
    foo.setv(idx, "Z");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I set a mutable string's value to a value from an array, and
I have this issue where I am trying to add values from one array
i want to set the value to a insert query from select query ,how
I have a question regarding passing a variable that is a char array from
I have a set of values that I'm pushing into an array in the
I need to write a generic procedure that set value for one column or
How do I set a value to only accept certain data in Python ?
how can i set default value in sonata admin bundle the data option is
How could I set the value of the Height property of a WPF control
how do I set the value of a field element after a form has

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.