JavaScript Remove Item From Comma Separated string

Today, We want to share with you JavaScript Remove Item From Comma Separated string.
In this post we will show you javascript split string by comma, hear for remove duplicates from comma separated string in javascript we will give you demo and example for implement.
In this post, we will learn about remove value from comma separated string javascript with an example.

JavaScript Remove Item From Comma Separated string

There are the Following The simple About JavaScript Remove Item From Comma Separated string Full Information With Example and source code.

As I will cover this Post with live Working example to develop , so the some major files and Directory structures for this example is following below.

  • index.html
Read Also:  Import Excel File Data In Database Using PHP

Remove empty values and duplicates from a comma separated string in JavaScript

Remove Item From Comma Separated string

index.html

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.html.We learn To Remove specific part of string from comma separated string using JavaScript

Read Also:  PHP Force File Download HTML button code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Remove specific part of string from comma separated string using JavaScript</title>
    <script type="text/javascript">
        function RemoveValue() {
            var number = document.getElementById("inpNum").value;
            var str = document.getElementById("studentNumber").innerHTML;
            var studentNumber = str.split(',');
            for (var i = 0; i < studentNumber.length; i++) {
                if (studentNumber[i] === number) {
                    studentNumber.splice(i, 1);
                }
            }
            document.getElementById("studentNumber").innerHTML = studentNumber;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Array <span id="studentNumber">1001,1002,1003,1005,1006,1007,1008,1009</span>
        <hr />
        Enter the number to be removed
        <input type="text" id="inpNum" name="name" value="" />
        <br />
        <input type="button" name="name" onclick="RemoveValue();" value="Remove" />
    </div>
    </form>
</body>
</html>

JavaScript Array Remove

remove value from comma separated values string

function spliceValueParam(list, value) {
  return list.replace(new RegExp(",?" + value + ",?"), function(match) {
      var begin_comma = match.charAt(0) === ',',
          last_comma;

      if (begin_comma &&
          (last_comma = match.charAt(match.length - 1) === ',')) {
        return ',';
      }
      return '';
    });
};


alert(spliceValueParam('1,2,3', '1')); // 2,3
alert(spliceValueParam('1,2,3', '2')); // 1,3
alert(spliceValueParam('1,2,3', '3')); // 1,2

Angular 6 CRUD Operations Application Tutorials
JavaScript Remove Item From Comma Separated
JavaScript Remove Item From Comma Separated

Read :

Read Also:  javascript split string by comma

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about remove duplicates from comma separated string in javascript.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Set Cookies Get Cookies Delete Cookies with PHP
  2. Read Also:  How to change date format in PHP Codeigniter?
  3. Read Also:  Add And Remove Text box Dynamically Using JavaScript Example
  4. Read Also:  How to allow only 10 digit number validation in Jquery?
  5. Read Also:  PHP Upload and Crop Image using jQuery Ajax
  6. Read Also:  Laravel 6 Get City Country By IP Address
  7. Read Also:  PHP Pagination demo – Pagination in PHP with example script
  8. Read Also:  PHP Force File Download HTML button code
  9. Read Also:  javascript split string by comma
  10. Read Also:  How to allow only 10 digit number validation in Jquery?
CLOSEX