{
test: /\.(png|svg|jpg|gif)$/,
use: [{
loader: 'file-loader',
options: {
name: f => {
let dirNameInsideAssets = path.relative(path.join(__dirname, 'src'), path.dirname(f));
return `${dirNameInsideAssets}/[name].[ext]`;
}
}
}],
},
import "./img/image.svg";
<img src="img/image.svg" alt=""/>
const nestedObject = { a: { b: { c: 3 } }, c: 1, b: 1 };
const str = "a.b.c";
const prop = str
.split(".")
.reduce(
(acc, current) => (acc[current] !== undefined ? acc[current] : acc),
nestedObject
);
console.log(prop);
var obj = { a: { b: { c: 3 } }, c: 1, b: 1 };
var str = 'a.b.c';
var value = eval('obj.'+str);
var obj = { a: { b: { c: 3 } }, c: 1, b: 1 };
var value = getPath(obj,'a.c');
function getPath(object, keyPath){
if( typeof keyPath === 'string' ) keyPath = keyPath.split(/\./);
if( !Array.isArray(keyPath) ) return undefined;
let key = keyPath.shift();
if( !key) return object;
if( !object.hasOwnProperty(key) ) return undefined;
if( keyPath.length === 0 ) return object[key];
return getPath(object[key],keyPath);
}
Object.entries(obj).filter(n => Number.isInteger(+n[0])).map(n => n[1]).join(';')
// или
Object.keys(obj).reduce((acc, n) => (`${+n}` === n && acc.push(obj[n]), acc), []).join(';')
// или
Array.from(obj).join(';')
// или
JSON.stringify(obj).match(/(?<="\d+":").*?(?=")/g).join(';')