Repeat Data in an Arrangement

0

I am using PHP and I have an arrangement that shows me the following:

0:{clave: "GTO", id: "45", nombre: "Guanajuato"}
1:{clave: "MEX", id: "76", nombre: "México"}
2:{clave: "EUA", id: "54", nombre: "Estados Unidos"}

What I want to do is to repeat the data I have in it, and in the new arrangement is as follows:

0:{clave: "GTO", id: "45", nombre: "Guanajuato"}
1:{clave: "GTO", id: "45", nombre: "Guanajuato"}
2:{clave: "MEX", id: "76", nombre: "México"}
3:{clave: "MEX", id: "76", nombre: "México"}
4:{clave: "EUA", id: "54", nombre: "Estados Unidos"}
5:{clave: "EUA", id: "54", nombre: "Estados Unidos"}

I get the data from Base de Datos , I use MVC , PHP , codeigniter , MySQL

Someone who can help me ?, would be very much appreciated.

    
asked by Soldier 16.08.2017 в 17:17
source

1 answer

2

This is a simple example that clones a JSON using JSON and another using JQUERY, I hope it works for you. The code is commented for better understanding.

<!DOCTYPE html>
<html>
<head>
    <title>Prueba</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js" ></script>
    <script type="text/javascript">
        (function ($) {

    //clonar usando JSON
    function fnCloneJSON (obj) {
        return JSON.parse(JSON.stringify(obj));
    }

    //clonar usando jQuery
    function fnClonejQuery (arr) {
        return $.extend(true, [], arr);
    }

//ejemplo de un formato JSON
var list = [{x:2, y:3}, {x:5, y:8}];

//clonamos
var clone1 = fnCloneJSON(list),
clone2 = fnClonejQuery(list);
//aqui concatenamos
var nuevo = clone1.concat(clone2);
console.log("Este es nuevo:", nuevo);

})(jQuery);
</script>
</body>
</html>
    
answered by 16.08.2017 / 17:54
source