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

127
Views
Not able to replace more than 2 array values

I want to replace my existing array with new array. But I am not able to add/replace more than 2 array values. After 2 values, it gets stuck even though the variables show multiple values in console.

function add_comments_in_editor() {
    var comment = '';
    // Get selected Action
    $('input[type=radio]:checked').each(function() {
      comment = '<strong>' + actions[$(this).attr('id')] + '</strong>';
      window.radioNew = '<strong>' + actions[$(this).attr('id')] + '</strong>';
      
    });
    // Get selected reason
    var arrCheck = [];
    window.newCheck = [];
    var arrOld = [];

    
    $('.voting_parameters input[type=checkbox]:checked').each(function() {
      var voting_parameter_id = $(this).attr('id');
      voting_parameters_array[$(this).attr('id')] + '</li>';
      arrCheck.push('<li>' + voting_parameters_array[$(this).attr('id')]);
      window.newCheck = arrCheck;
      // Get selected reasons parameters
      $(this).parent().next('.voting_parameter_reasons').find('input:checkbox').each(function() {
        if ($(this).is(':checked')) {
          var voting_parameter_reasons_id = $(this).attr('id');
          var reason_index = (voting_parameter_reasons_array[voting_parameter_id].map(function(item) {
            return item.voting_parameter_reason_id;
          }).indexOf(voting_parameter_reasons_id))

      voting_parameter_reasons_array[voting_parameter_id][reason_index]['reason_name'] + '</li></ul>';
        }
      });

    var radioOld = window.oldRadio || '';
    var checkOld = window.oldCheck || '';

    tinyMCE.activeEditor.setContent(tinyMCE.activeEditor.getContent().replace(checkOld, window.newCheck).replace(radioOld, window.radioNew));

    window.oldRadio = '<p><strong>' + actions[$('input[type=radio]:checked').attr('id')] + '</strong></p>';
    arrOld.push('<li>' + voting_parameters_array[$('.voting_parameters input[type=checkbox]:checked').attr('id')]);
    window.oldCheck = arrCheck;
  }

I just need to see why I am not able to replace more than 2 values.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

String.prototype.replaceAll()

Ref: https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll

tinyMCE.activeEditor.getContent().replaceAll(checkOld, window.newCheck)

about 4 years ago · Santiago Gelvez Report
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!