0

So i have this:

$('#chapters').filter(function() {
            var volume_elms = $('.volume');
            var chapter_elms = $('.chlist');

            for (var i = 0, l = volume_elms.length; i < l; ++i) {
                var elm = $(volume_elms[i]);
                var celm = $(chapter_elms[i]);

                var volume_name = elm.first().text();
                var volume_id = elm.first().text().split('removeMe');

                var vlist = {
                    id: volume_id,
                    name: volume_name,
                    chapters: []
                };

                for (var j = 0, ll = celm.children().length; j < ll; ++j) {
                    var chapter = $(celm.children()[j]);
                    var chapter_name = chapter.first().text().split('\r\n')[4].trim();

                    vlist.chapters.push({
                        name: chapter_name
                    });
                }

                json.volumes.push(vlist);
            }
        });

        res.send(json);

And i want to remove some characters from volume_id and i know that .split('removeMe') removes that but it only removes it in that order and you can only use it once

So how can i remove multiple characters and also avoid it that it becomes an array (output is json)

meiwaku
  • 15
  • 5

2 Answers2

1

You can use regex to find multiple matches, separated by '|' (or)

value.replace(/FilterMe|FilterMeToo/g, "");
0

You can replace multiple words Like

.filter('words', function() {
    return function (value) {
        return (!value) ? '' : value.replace('FilterMe', '').replace('FilterMeTwo', '').replace('FilterMeThree', '');
    };
  });
Bhavin Solanki
  • 4,740
  • 3
  • 26
  • 46
  • Ah Thanks Do you maybe also know how i can remove characters from this `var volume_id = elm.first().text();` Something like .split('RemoveMe') but i can only use this once also when i use split my json turns into an array – meiwaku Jul 29 '15 at 19:19
  • sorry, i am not getting you can you please post another question for this... Also don't forget to accept or upvote for my answer – Bhavin Solanki Jul 29 '15 at 19:22