관리 메뉴

투덜이 개발자

[JavaScript] JavaScript Serialize function 본문

Program Language/JavaScript & Jquery

[JavaScript] JavaScript Serialize function

엠투 2022. 6. 27. 09:58
반응형

JavaScript Serialize function 

function changeSerialize(values, k, v) {
   let found = false;
   
   for (let i = 0; i < values.length && !found; i++) {
      if (values[i].name === k) {
         values[i].value = v;
         found = true;
      }
   }
   
   if (!found) {
      values.push(
         {
            name: k,
            value: v
         }
      );
   }
   
   return values;
   
}

 

jQuery 를 이용하면 더 쉽게 이용가능함 

https://api.jquery.com/serialize/

 

.serialize() | jQuery API Documentation

Description: Encode a set of form elements as a string for submission. The .serialize() method creates a text string in standard URL-encoded notation. It can act on a jQuery object that has selected individual form controls, such as , , and : $( "input, te

api.jquery.com

 

반응형