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

0

98
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 3 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 3 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 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