Stack Exchange
query string value repeated while using forEach loop (javascript)
I am making a database website using AngularJs, mongodb, and restheart.

I design a table that if I input text in any of the five input area, the data with the keywords will show up. 
 <input types="text" ng-model="query.uniport_AC" ng-change="change()">
 ......
 <input types="text" ng-model="query.site" ng-change="change()">

and in the javascript, my code is 
$scope.change = function(){
        var url = "";
        angular.forEach($scope.query, function(value, key) {
            if(!angular.isUndefined(value)){
                    url = url + "'"+key+"':{'$regex':'(?i)"+value+".*'},";
                    };      
            test = "http...&filter={" +url+ "}";
            $http.get(test+"}").then(
                        function(res){
                            $scope.db = res.data._embedded["rh:doc"];
                            $scope.pages = res.data._total_pages;
                            $scope.sizes = res.data._size;
                            console.log(res);           
                            },
                        function(err){
                            console.log(err);
                        }   
                    );

My problem is, let say I input a and g in the first 2 input area, respectively, I wish to create a string like this
http...filter={'uniprot_AC':{'$regex':'(?i)a.*'},'gene_name':{'$regex':'(?i)g.*'},

However, I get a string like this
http...filter={'uniprot_AC':{'$regex':'(?i)a.*'},'uniprot_AC':{'$regex':'(?i)a.*'},'gene_name':{'$regex':'(?i)g.*'},'gene_name':{'$regex':'(?i)g.*'},

The url (let say 'uniprot_AC':{'$regex':'(?i)a.*'},) is repeated one more times. Can anyone point what is wrong with my code?

$scope.change2 = function () { ... }  and the front end code ng-change = change(), are they different functions or just a typo?

typo. I will modified it. Thanks.

What does $scope.query hold?

{"uniport": an input text; "gene_name": an input text; "description: an input text; "species": an input tex; "site": an input text}. Basically, it is an array that link the five input.

Can you create a plunker link for this ?

And also, when does the test variable declare?

What is a plunker link? How to make that...?
