• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

265
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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error