JSFiddle - React, Tailwind, and code Playground
by andrei
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
JavaScript
var belarus = [];
belarus.push({ name: "Vladimir", from: belarus });
belarus.push({ name: "Andrei", from: belarus });
var objects = [];
var checker = function(obj) {
if (objects.indexOf(obj) > -1) {
return true;
} else {
objects.push(obj);
return false;
}
};
var cleanUp = function(obj) {
var value;
if (_.isArray(obj)) {
value = checker(obj) ? "[CIRCULAR-ARRAY]" : _.map(obj, cleanUp);
} else if (_.isObject(obj)) {
value = checker(obj) ? "[CIRCULAR-OBJECT]" : _.mapObject(obj, cleanUp);
} else {
value = obj;
}
return value;
}
console.log(cleanUp(belarus));