Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
copy values of an array to another array

I want to copy the values of genders[x] in another array in JavaScript. If genders[x] is "m" I want to copy the values in a seperate array which is called genders[m] and if it is "f" I want to copy the values in the array genders[f].

m = 0;
f = 0;
x = 0;

function add_element_to_array() {
    usernames[x] = document.getElementById("name").value;
    ages[x] = document.getElementById("age").value;
    genders[x] = document.getElementById("gender").value;

    gendersM[m] = document.getElementById("gender").value
    gendersF[f] = document.getElementById("gender").value
        if ( (correctEingabe == true) && (age == true) ){
            ++x;
                
        if (genders[x] == "m") {
            ++m;
        } 
        if (genders[x] == "f") {
            ++f;
        } 
        else {
            deleteLastArray();
        }   
 }

The first part works perfectly so just this part is important. But somehow it doesn't work. I would be very thankful for some help.

     if (genders[x] == "m") {
        ++m;
    } 
    if (genders[x] == "f") {
        ++f;
    } 
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!